How to move objects?

Hi!

How can I move objects correctly? I have written this part of code, which will be shown in the attached file.

 

Around this piece of code, a for-loop will iterate all objects in the hierarchy. The topic is to move certain objects below the object with the absolute number 27602.

If I comment the move-function out, the "print if if if" will be shown in the interaction window, but if I uncomment the move function, the "print if if if" won't be shown at this certain objects. However: Two of this objects will be moved correctly at the first run of the script. If I start the script a second time, the next 1 or 2 (I don't know exactly...) objects will be moved also correctly; and so on...

The variable lobj_DoorsHexDTC is the variable in the for-loop which will be iterated. This variable is the object-pointer.
 

The same Problem, I think is in the else-case of the first if-statement. In this case, the script reads the chapter from Atrribute p_ODX_Group an the corresponding Absolute Number.

I assume, that the move-function isn't used correctly in my code....
 

THX for your help!


bandchef - Thu Sep 26 09:19:04 EDT 2013

Re: How to move objects?
llandale - Thu Sep 26 10:56:03 EDT 2013

Like my Mommy used to say, don't modify loop control variables inside the loop.

Analogy: the folliing code prints 0 2 4.  Notice we adjust the loop variable inside the loop.

  • int i
  • for (i=0; i<5; i++)
  • {  print (i++) "\t"
  • } 

I now assert the following two loops are equivalent:

  • [1]
  • for o in m do{ }
  • [2]
  • o = first(m)
  • while(!null o){print identifier(o) "\t"; o = next(o)}

If so, when you move your loop control object then you are changing the loop, as the "next(o)" changes when you move it.

I'd have your first loop FIND objects that need moving and put them into some Skip skpMove list; perhaps KEY Objectt to move; DATA Object to move after.  Have a 2nd loop to actually do the moving.

As for your 2nd problem; you are doing this:

  • int i
  • for (i=0; i<5; i++)
  • {  for (i=0; i<6; i++)
  •    {  print i "\t"
  •    }
  •    print "Outside: " i "\t"
  • }

Your for o in m loop starting line 102 conflicts with the outer one startong line 17.

Try this stucture instead:

  • Skip skpObjects = create
  • for o in m do{put(skpObjects, o, o)}
  • for o in m do
  • {  if
  •    { bla bla bla}
  •    else
  •    {  for o in skpObjects do{}
  •    }
  • }

-Louie

Kids these days!